import java.util.Scanner;

	
public class ManageBooking {
	private Scanner sc = new Scanner(System.in);
	public ManageBooking()
	{
		
	}
	
	public void book(int movieId, int cineplexId, int showId)
	{
	
		BookingItem bookingItem = new BookingItem();
		// Read the Goer Information //
		System.out.println("Please insert your name: ");
		String name = sc.next();
		System.out.println("Please insert your email: ");
		String email = sc.next();
		System.out.println("Please insert your mobile number: ");
		String mobileNumber = sc.next();
		System.out.println("The price of ticket will depend on you age: ");
		System.out.println("Please insert your class: ");
		System.out.println("1.Child ( <12 years old) ");
		System.out.println("2.Student (student card will be check at ticket counter) ");
		System.out.println("3.Adult");
		System.out.println("4.Senior citizen");
		int type = sc.nextInt();
		
		// Create new GoerItem to store value//
		GoersItem goer = new GoersItem();
		goer.setGoerEmail(email);
		goer.setGoerMobile(mobileNumber);
		goer.setGoerName(name);
		if (type==3 )
			goer.setGoerType(0);
		else
			goer.setGoerType(-1);
		// Check Goer exists or new One, if new => add to the goer List, if existed => add booking to the booking list of Goer//
		if (MovieApp.goerList.size()==0)
			MovieApp.goerList.add(goer);
		else
		for (int i=0; i<MovieApp.goerList.size();i++)
			if (MovieApp.goerList.get(i).getGoerEmail().trim().equals(goer.getGoerEmail().trim())==true)
				break;			
			else 
				MovieApp.goerList.add(goer);
		// set Attribute to Booking Item//
		bookingItem.setGoers(goer);
		bookingItem.setMovie(MovieApp.movieList.get(movieId));
		bookingItem.setShowItem(MovieApp.cineplexList.get(cineplexId).getShowList().get(showId));
		// Do booking work //
		MovieApp.cineplexList.get(cineplexId).getShowList().get(showId).getCinemaItem().printCinema();
		System.out.println("Please insert your choice (row): ");
		char temp = sc.next().toUpperCase().trim().charAt(0);
		int row = temp-64;
		System.out.println("Please insert your choice (column): ");
		int column = sc.nextInt();
		MovieApp.cineplexList.get(cineplexId).getShowList().get(showId).getCinemaItem().assignSeat(row-1, column-1);
		MovieApp.cineplexList.get(cineplexId).getShowList().get(showId).getCinemaItem().printCinema();
		
		bookingItem.setSeatNumber(temp+Integer.toString(column));
	
		// Set Value to ticket//
		bookingItem.setAmountPayment(setTicketPrice(MovieApp.movieList.get(movieId).getMovieClass(),goer.getGoerType(), MovieApp.cineplexList.get(cineplexId).getShowList().get(showId).getCinemaClass()));
		
		// add booking item to appropriate goer//
		for (int i =0; i<MovieApp.goerList.size();i++)
			if (MovieApp.goerList.get(i).getGoerEmail().trim().equals(goer.getGoerEmail().trim()))
					MovieApp.goerList.get(i).getTheListOfBooking().add(bookingItem);
		
		
		MovieApp.cineplexList.get(cineplexId).getShowList().get(showId).getBookingListOfShow().add(bookingItem);
		// print out the invoice //
		
		System.out.println("Do you want to print out the invoice (y/n): ");
		char choice = sc.next().trim().toLowerCase().charAt(0);
		if (choice == 'y')
		{
			System.out.println(bookingItem.getTransactionId());
			System.out.println("Name      : "+bookingItem.getGoer().getGoersName());
			System.out.println("Mobile    : "+bookingItem.getGoer().getGoerMobile());
			System.out.println("Email     : "+bookingItem.getGoer().getGoerEmail());
			System.out.println("Movie Name: "+bookingItem.getMovie().getMovieName());
			System.out.println("Movie Type: "+bookingItem.getMovie().getMovieType());
			System.out.println("Seat      : "+bookingItem.getSeatNumber());
			System.out.println("Price     : "+bookingItem.getAmountPayment());
			System.out.println();
		}
	}
	
	
	public void printBookingHistory(int goerid)
	{
		for ( int i=0; i<MovieApp.goerList.get(goerid).getTheListOfBooking().size();i++)
		{
			System.out.println(MovieApp.goerList.get(goerid).getTheListOfBooking().get(i).getTransactionId());
			System.out.println("Name      	: "+MovieApp.goerList.get(goerid).getTheListOfBooking().get(i).getGoer().getGoersName());
			System.out.println("Mobile    	: "+MovieApp.goerList.get(goerid).getTheListOfBooking().get(i).getGoer().getGoerMobile());
			System.out.println("Email     	: "+MovieApp.goerList.get(goerid).getTheListOfBooking().get(i).getGoer().getGoerEmail());
			System.out.println("Movie Name	: "+MovieApp.goerList.get(goerid).getTheListOfBooking().get(i).getMovie().getMovieName());
			System.out.println("Movie Type	: "+MovieApp.goerList.get(goerid).getTheListOfBooking().get(i).getMovie().getMovieType());
			System.out.println("Cineplex    : "+MovieApp.goerList.get(goerid).getTheListOfBooking().get(i).getShowItem().getCineplex());
			System.out.println("Cinema      : "+MovieApp.goerList.get(goerid).getTheListOfBooking().get(i).getShowItem().getCinemaItem().getCinemaName());
			System.out.println("Seat      	: "+MovieApp.goerList.get(goerid).getTheListOfBooking().get(i).getSeatNumber());
			System.out.println("Price     	: "+MovieApp.goerList.get(goerid).getTheListOfBooking().get(i).getAmountPayment());
			System.out.println();
		}
	}
	
	public double setTicketPrice(int movieType, int goerClass, int cinemaClass)
	{
		double price = MovieApp.price;
		price = price *(double)(1+(double)movieType/10);
		price = price *(double)(1+(double)cinemaClass/10);
		price = price *(double)(1+(double)goerClass/10);
		price = price *(double)(1+ (double)MovieApp.dayClass/10);
		return price;
	}
}
